package cn.edu.henu.team.fragments;

import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;
import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;
import cn.edu.henu.team.R;
import cn.edu.henu.team.adapter.HomePagerAdapter;
import cn.edu.henu.team.base.BaseFragment;

public class fragment2 extends BaseFragment {
    private fragment2 mContext;
    private TabLayout mTabLayout;
    private ViewPager2 mViewPager2;
    private List<String> mData = new ArrayList<>();
    private List<Fragment> mFragments = new ArrayList<>();

    public static fragment2 newInstance() {
        fragment2 fragment = new fragment2();
        return fragment;
    }

    @Override
    protected int initLayout() {
        return R.layout.fragment_2;
    }

    @Override
    protected void initView() {
        mContext = fragment2.this;

        mData.add("测试");
        mData.add("药品清单");
        mData.add("病友圈");
        mData.add("我的");
        mFragments.add(fragment2_test.newInstance());
        mFragments.add(fragment2_drugList.newInstance());
        mFragments.add(fragment2_circle.newInstance());
        mFragments.add(fragment2_mine.newInstance());

        mTabLayout = mRootView.findViewById(R.id.fragment2_indicator);
        mViewPager2 = mRootView.findViewById(R.id.fragment2_viewpager2);

        HomePagerAdapter homePagerAdapter = new HomePagerAdapter(getActivity(), mData,mFragments);
       mViewPager2.setOffscreenPageLimit(mData.size()); //预加载
        mViewPager2.setAdapter(homePagerAdapter);
        new TabLayoutMediator(mTabLayout, mViewPager2, new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                tab.setText(mData.get(position));
            }
        }).attach();
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void clickEvents() {

    }
}
